package com.sk.bilibili.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * @author 邵康
 * @date 2021/11/25 22:56
 */
@Component
public class DbUtils {

    @Autowired
    private JdbcTemplate template;
    private static final String CHANGE_NUM_SQL="update %s set %s = %s + %d where id = %d";
    private static final String CLEAR_RECORD_SQL="delete from %s where create_date < %d";

    public void changeNum(String table,String column,Integer num,Integer id){
        template.update(String.format(CHANGE_NUM_SQL,table,column,column,num,id));
    }

    public void clearRecord(String table,long time){
        template.update(String.format(CLEAR_RECORD_SQL,table,time));
    }

}
